/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */
#ifndef PLMULTIBOOT_INFORMATION_H
#define PLMULTIBOOT_INFORMATION_H

#include <cstddef>
using namespace std;

/**
 * Multiboot flag for memory information.
 */
#define MULTIBOOT_FLAG_MEM     0x001
/**
 * Multiboot flag for device information.
 */
#define MULTIBOOT_FLAG_DEVICE  0x002
/**
 * Multiboot flag for comandline information.
 */
#define MULTIBOOT_FLAG_CMDLINE 0x004
/**
 * Multiboot flag for module information.
 */
#define MULTIBOOT_FLAG_MODS    0x008
/**
 * Multiboot flag for aout information.
 */
#define MULTIBOOT_FLAG_AOUT    0x010
/**
 * Multiboot flag for elf information.
 */
#define MULTIBOOT_FLAG_ELF     0x020
/**
 * Multiboot flag for memory map information.
 */
#define MULTIBOOT_FLAG_MMAP    0x040
/**
 * Multiboot flag for config information.
 */
#define MULTIBOOT_FLAG_CONFIG  0x080
/**
 * Multiboot flag for loader information.
 */
#define MULTIBOOT_FLAG_LOADER  0x100
/**
 * Multiboot flag for APM information.
 */
#define MULTIBOOT_FLAG_APM     0x200
/**
 * Multiboot flag for VBE information.
 */
#define MULTIBOOT_FLAG_VBE     0x400

struct Multiboot_AOUT_SymbolTable {
	/**
	 * Table size.
	 */
	uint32_t tabsize;
	/**
	 * String size.
	 */
	uint32_t strsize;
	/**
	 * Address.
	 */
	uint32_t addr;
	/**
	 * Reserved.
	 */
	uint32_t reserved;
};

struct Multiboot_ELF_SectionHeaderTable {
	/**
	 * Number of table entries.
	 */
	uint32_t num;
	/**
	 * The size of the table.
	 */
	uint32_t size;
	/**
	 * The address.
	 */
	uint32_t addr;
	/**
	 *
	 */
	uint32_t shndx;
};

/**
 * Struct for multiboot information.
 */
struct Multiboot_info {
	/**
	 * The multiboot flags.
	 */
	uint32_t flags;
	/**
	 * Size of the lower memory.
	 */
	uint32_t mem_lower;
	/**
	 * Size of the upper memory.
	 */
	uint32_t mem_upper;
	/**
	 * The boot device.
	 */
	uint32_t boot_device;
	/**
	 * The comandline.
	 */
	uint32_t cmdline;
	/**
	 * The number of modules.
	 */
	uint32_t mods_count;
	/**
	 * The address of the modules map.
	 */
	uint32_t mods_addr;
	union {
		Multiboot_AOUT_SymbolTable aoutsym;
		Multiboot_ELF_SectionHeaderTable elfsym;
	} u;
	/**
	 * Memory map size.
	 */
	uint32_t mmap_length;
	/**
	 * Address of the memory map.
	 */
	uint32_t mmap_addr;

	/**
	 * The number of devices in the device list.
	 */
	uint32_t drives_length;
	/**
	 * The address of the table with the devices.
	 */
	uint32_t drives_addr;

	/**
	 * The config table.
	 */
	uint32_t config_table;
	/**
	 * The name of the boot loader.
	 */
	uint32_t boot_loader_name;
	/**
	 * The APM table.
	 */
	uint32_t apm_table;

	/**
	 * VBE control information.
	 */
	uint32_t vbe_control_info;
	/**
	 * VBE mode information.
	 */
	uint32_t vbe_mode_info;
	/**
	 * The VBE mode.
	 */
	uint16_t vbe_mode;
	/**
	 * VBE interface seg.
	 */
	uint16_t vbe_interface_seg;
	/**
	 * VBE interface offset.
	 */
	uint16_t vbe_interface_off;
	/**
	 * VBE interface length.
	 */
	uint16_t vbe_interface_len;
};

/**
 * A memory map entry from the multiboot information.
 */
struct Multiboot_MemoryMapEntry {
	/**
	 * The size of the entry.
	 */
	uint32_t size;
	/**
	 * The address of the entry.
	 */
	uint32_t addr_low;
	uint32_t addr_high;
	/**
	 * The length of the entry.
	 */
	uint32_t len_low;
	uint32_t len_high;
	/**
	 * The type of the entry.
	 */
	uint32_t type;
};

/**
 * The types of a memory map entry.
 */
enum Multiboot_MemoryEntryType {
	/**
	 * The memory was avilable and can be used.
	 */
	Multiboot_MemoryEntryType_Avilable				= 1,
	/**
	 * The memory was reserved for system internal use.
	 */
	Multiboot_MemoryEntryType_Reserved				= 2,
	/**
	 * The memory was reserved for system ACPI Reclaimable use.
	 */
	Multiboot_MemoryEntryType_ACPI_Reclaimable	= 3,
	/**
	 * The memory was reserved for system ACPI NVS use.
	 */
	Multiboot_MemoryEntryType_ACPI_NVS				= 4,
	/**
	 * The memory was reserved as bad.
	 */
	Multiboot_MemoryEntryType_Bad						= 5
};

/**
 * Module information list.
 */
struct Multiboot_moduleList {
	/**
	 * The start address for the module.
	 */
	uint32_t mod_start;
	/**
	 * The end address for the module.
	 */
	uint32_t mod_end;
	/**
	 * The commandline from the module.
	 */
	uint32_t mod_cmdline;
	/**
	 * Reserved.
	 */
	uint32_t mod_reserved;
};

#endif
